package com.sf.admin.controller.sys;

import com.sf.admin.model.po.Role;
import com.sf.admin.model.vo.Msg;
import com.sf.admin.service.RoleService;
import com.sf.admin.tools.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("sys/role")
public class RoleController {

	@Autowired
	private RoleService roleService;
	@Autowired
	private IdWorker idWorker;

	@GetMapping
	public List<Role> roleList(){
		return roleService.selectList();
	}

	@PostMapping
	public Msg add(@RequestBody Role role){
		long id = idWorker.nextId();
		role.setRoleId(id);
		role.setRoleSort(1);
		role.setStatus("1");
		role.setCreateBy("lidongxu");
		role.setCreateTime(new Date());
		return roleService.insert(role);
	}

	@Bean
	public IdWorker idWorker(){
		return new IdWorker();
	}
}
